package com.scm.servlet.pomain;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSONArray;
import com.scm.page.Page;
import com.scm.model.Pomain;
import com.scm.service.PomainService;


@WebServlet("/main/pomain/queryPomain")
public class QueryPomainServlet extends HttpServlet {
	private static final long serialVersionUID = -5565842992061003957L;
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		req.setCharacterEncoding("UTF-8");
		resp.setCharacterEncoding("UTF-8");
		String currentpagestr = req.getParameter("currentPage");
		String poId = req.getParameter("poId");
		String startDate = req.getParameter("startDate");
		String endDate =req.getParameter("endDate");
		String venderName = req.getParameter("venderName");
		String payType = req.getParameter("payType");
		String status = req.getParameter("status");
		int currentPage = 1;
		if(currentpagestr != null && currentpagestr.matches("\\d++")) {
			currentPage = Integer.parseInt(currentpagestr);
		}
		Map<String,String> querymap = new HashMap<String,String>();
		querymap.put("poId", poId);
		querymap.put("startDate", startDate);
		querymap.put("endDate", endDate);
		querymap.put("venderName", venderName);
		querymap.put("payType", payType);
		querymap.put("status", status);
		try {
			
			Page<Pomain> page = new PomainService().selectPage(currentPage, querymap);
			String json= JSONArray.toJSONString(page);
			
			PrintWriter pw=resp.getWriter();
			pw.print(json);
			pw.flush();
			pw.close();
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(req, resp);
	}

}
